#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json

def generate_exposure_commands(expst_times, imagename, output_file="exposure_batch.txt"):
    """
    批量生成曝光指令
    
    Args:
        expst_times: EXPST_TIME值的数组
        imagename: IMAGENAME的值
        output_file: 输出文件名
    """
    
    # 基础模板参数
    base_params = {
        "ID": 302,
        "CamID": 25078,
        "EXP_TYPE": "sf",
        "IMG_INFO": {"OBJ_NAME": "0", "FW_NAME": "g", "IMG_NUM": 3}
    }
    
    commands = []
    
    for i, expst_time in enumerate(expst_times):
        # 生成TIME值（递增）
        time_value = i + 1
        
        # 构建命令字符串，IMG_INFO使用JSON格式
        img_info_json = json.dumps(base_params["IMG_INFO"])
        command = f'<ID={base_params["ID"]}><CamID={base_params["CamID"]}><EXPST_TIME={expst_time}><EXP_TYPE={base_params["EXP_TYPE"]}><IMAGENAME={imagename}><TIME={time_value}><IMG_INFO={img_info_json}>'
        commands.append(command)
    
    # 写入文件
    with open(output_file, 'w', encoding='utf-8') as f:
        for command in commands:
            f.write(command + '\n')
    
    print(f"已生成 {len(commands)} 条曝光指令到文件: {output_file}")
    return commands

if __name__ == "__main__":
    # 设置EXPST_TIME数组 - 你可以修改这个数组
    expst_times = [1, 2, 3, 4, 5]
    
    # 设置IMAGENAME - 你可以修改这个值
    imagename = "PTC_flat.fits"
    
    # 生成曝光指令
    commands = generate_exposure_commands(expst_times, imagename)
    